package com.base.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.base.service.ScheduledTaskService;
import com.base.utils.CronUtils;
import com.base.vo.SpringScheduledCron;
import com.base.mapper.SpringScheduledCronMapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

/**
 *
 */
@Service
public class ScheduledTaskServiceImpl extends ServiceImpl<SpringScheduledCronMapper, SpringScheduledCron>
        implements ScheduledTaskService {

    @Override
    public boolean saveOrUpdate(SpringScheduledCron scheduledCron) {
        if (!CronUtils.isValidExpression(scheduledCron.getCronExpression())) {
            throw new IllegalArgumentException("保存失败,cron表达式不正确,请检查！" + scheduledCron.getCronExpression());
        }
        Assert.notNull(scheduledCron, "保存失败，对象为空！");
        if (!StringUtils.isNotBlank(scheduledCron.getCronKey())) {
            throw new IllegalArgumentException("保存失败，完整类名不能为空！" + scheduledCron);
        }
        return super.saveOrUpdate(scheduledCron);
    }
}




